package com.myfoon.view.application;

import javax.faces.application.ViewHandler;
import javax.faces.application.ViewHandlerWrapper;
import javax.faces.context.FacesContext;


public class PersistLocaleViewHandler extends ViewHandlerWrapper {
    public static final String LOCALE_PARAMETER = "_lang";

    private ViewHandler wrapped;

    public PersistLocaleViewHandler(ViewHandler original) {
        wrapped = original;
    }

    /**
     * Add the current locale to the redirection URL so that the language is maintained.
     * 
     * @param context the current FacesContext instance
     * @param viewId the viewId where the user will be redirected to
     * 
     * @return the url to the specified view id, maintaining the locale.
     */
    
    
    @Override    
    public String getActionURL(FacesContext context, String viewId) {
        return super.getActionURL(context, viewId);
        /*
        String url = super.getActionURL(context, viewId);

        String locale = context.getViewRoot().getLocale().toString();
        
        return EncoderUtils.appendURLArguments(url, 
                                               new String[] { LOCALE_PARAMETER, 
                                                              locale });
        */
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected ViewHandler getWrapped() {
        return wrapped;
    }
}
